package com.and.bean;


import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;

import org.compass.annotations.Searchable;
/**
 * 角色
 * gouanming
 * gouanming11@yahoo.com.cn
 * 安的软件开发
 */
@Entity @Searchable(root=false)//通过这个注解,指明该类跟lucene中的document映射
public class Role implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8240707704774321988L;
	private Integer id;
	private String name;
	private String descn;
	private Set<Users> users=new HashSet<Users>();
	
	
	
	public Role(){}
	
	public Role(String name) {
		super();
		this.name = name;
	}
	@ManyToMany(cascade=CascadeType.REFRESH,mappedBy="role")
	public Set<Users> getUsers() {
		return users;
	}
	public void setUsers(Set<Users> users) {
		this.users = users;
	}
	public String getDescn() {
		return descn;
	}
	public void setDescn(String descn) {
		this.descn = descn;
	}
	@Id @GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=10,nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
	
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Role other = (Role) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
}
